<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

jimport( 'joomla.application.component.view' );

class JAJobBoardViewJAJobs extends JAView
{
    /**
     * Display the view
     */
    function display($tmpl = null)
    {
    	global $option;
    	require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'asset'.DS.'rendfield.php');
		$task = JRequest::getVar("task", '');
		switch ($task){
			case 'add':
			case 'edit':				
				JAJobBoardViewJAJobs::displayForm();
				break;	
			case 'edit_code':				
				JAJobBoardViewJAJobs::displayForm();
				break;		
			default:
				JAJobBoardViewJAJobs::displayListItems();
		}
		
		parent::display($tmpl);
  	}
  	
  	
  	/**
  	* Display List of items
  	*/
  	function displayListItems(){  		
  		global $mainframe, $option;        
        // get data items
        $model = &$this->getModel();               
         
       	$items = $model->getItems();  
       
       	$fieldEditList = $model->getEditFieldList();
       	$fieldList = $model->getFieldList();
       
		$pagination = &$this->get('Pagination');       
        
        $lists = $this->_getViewLists($fieldEditList);        
        
        $ordering = true;        
        
        $this->assignRef('items', $items);
        $this->assignRef('pagination', $pagination);
        $this->assignRef('fieldlist', $fieldList);
        $this->assignRef('lists', $lists);
        $this->assignRef('ordering', $ordering );                
  	}
  	/**
  	* Display edit form
  	*/
  	function displayForm(){  	    
  		global $option;
  		
  		$model = &$this->getModel();
  	    $item = &$this->get('Item');  	
		if (JRequest::getVar('postback',false))
		{
			$post = JRequest::get('post');
			
			$item->bind($post);
			
		}
  	    $temp = $this->getModel('jajobs');
  	    $fieldEditList = $temp->getEditFieldList();
		
		$item = parse_content_item($item, $fieldEditList);		
		
		$this->assignRef('fieldlist', $fieldEditList);
  	    $this->assignRef('option', $option);
  	    $this->assignRef('item', $item);
  	    build_relation_value_JS();
	}
	
	function &_getViewLists($fieldList)
	{
		global $mainframe, $option,$jbconfig;

		$db = &JFactory::getDBO();
		
        $lists['is_hotjob']	= $mainframe->getUserStateFromRequest( $option.".jajobs.is_hotjob",	'is_hotjob',		'',	'cmd' );
        if($lists['is_hotjob']=='') $lists['is_hotjob'] = -1;
		$filter_order		= $mainframe->getUserStateFromRequest( $option.".jajobs.filter_order",		'filter_order',		"a.".$jbconfig['posts']->get('filter_order'),	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $option.".jajobs.filter_order_Dir",	'filter_order_Dir',	$jbconfig['posts']->get('filter_order_Dir'),			'word' );
		$search				= $mainframe->getUserStateFromRequest( $option.".jajobs.search",			'search',			'',				'string' );
		$search				= JString::strtolower( $search );        
				
		// table ordering
		$lists['order_Dir']	= $filter_order_Dir;
		$lists['order']		= $filter_order;
		
		/* search filter */
		$lists['search']= $search;
		$item = new stdClass();
		
		foreach ($fieldList as $field){
			if($field->is_on_filter && ($field->field_type=='SELECT'||$field->field_type=='MSELECT')){
				$item->{$field->field_name} = $mainframe->getUserStateFromRequest( $option.".jajobs.".$field->field_name,   $field->field_name,   '', 'string' );
				$lists['filter'][$field->field_name] = rendfield($item, $field, true,false,true);
			}
		}	

        // filter_state
        $lists['option']    = $option;
		
		return $lists;
	}		
}
?>